# Maintainer: Konstantin Podsvirov <konstantin@podsvirov.su>

_basename=create-tauri-app
_realname=cargo-${_basename}
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=4.5.10
pkgrel=1
pkgdesc="Rapidly scaffold out a new tauri app project (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://github.com/tauri-apps/create-tauri-app"
msys2_references=(
  'purl: pkg:cargo/create-tauri-app'
)
license=('spdx:MIT OR Apache-2.0')
makedepends=("${MINGW_PACKAGE_PREFIX}-rust")
source=("${url}/archive/${_basename}-v${pkgver}/${_basename}-${_basename}-v${pkgver}.tar.gz")
sha256sums=('05005021724e09e73aaf24f1e59e2820493d784d4f62eaeaa64618df95e351d5')

prepare() {
  cd "${srcdir}/${_basename}-${_basename}-v${pkgver}"

  "${MINGW_PREFIX}/bin/cargo.exe" fetch --locked --target "$(rustc -vV | sed -n 's/host: //p')"
}

build() {
  cp -r "${_basename}-${_basename}-v${pkgver}" "build-${MSYSTEM}"
  cd "build-${MSYSTEM}"

  "${MINGW_PREFIX}/bin/cargo.exe" build \
    --release \
    --frozen
}

check() {
  cd "${srcdir}/build-${MSYSTEM}"

  "${MINGW_PREFIX}/bin/cargo.exe" test \
    --release \
    --frozen
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"

  install -Dm755 "target/release/${_realname}.exe" "${pkgdir}${MINGW_PREFIX}/bin/${_realname}.exe"
  install -Dm644 "README.md" "${pkgdir}${MINGW_PREFIX}/share/doc/${_realname}/README.md"
  install -Dm644 "LICENSE_MIT" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE_MIT"
  install -Dm644 "LICENSE_APACHE-2.0" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE_APACHE-2.0"
}
